package cn.dnui_lxx432.dnuifood_16110100432.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.dnui_lxx432.dnuifood_16110100432.JavaBean.comments;
import cn.dnui_lxx432.dnuifood_16110100432.R;

public class CommentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<comments> mDataList;
    private LayoutInflater mLayoutInflater;
    private String id;

    public CommentAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
        notifyDataSetChanged();
    }



    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.comments_adapter,parent,false);

        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        final comments entity = (comments)mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.content.setText(entity.getContent());
        viewHolder.comment_username.setText(entity.getComment_username());
        viewHolder.comment_time.setText(entity.getComment_time());
    }

    @Override
    public int getItemCount() {
        if (mDataList==null)
            return 0;
        else
            return mDataList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView content,comment_username,comment_time;
        public ViewHolder(View view) {
            super(view);
            content=view.findViewById(R.id.comment_text);
            comment_username=view.findViewById(R.id.comment_username);
            comment_time=view.findViewById(R.id.comment_time);
        }
    }
}


